package br.ufc.ck0017.ir.tree;

import java.util.ArrayList;
import java.util.List;

public class BINOP implements IRNode {
    private final Operator operator;
    private final IRNode leftOperand;
    private final IRNode rightOperand;

    public enum Operator {
        PLUS,
        MINUS,
        MUL,
        DIV,
        AND,
        OR,
        LSHIFT,
        RSHIFT,
        ARSHIFT,
        XOR;
    }

    BINOP(Operator operator, IRNode leftOperand, IRNode rightOperand) {
        this.operator = operator;
        this.leftOperand = leftOperand;
        this.rightOperand = rightOperand;
    }

    @Override
    public List<IRNode> getChildren() {
        List<IRNode> children = new ArrayList<>();
        children.add(leftOperand);
        children.add(rightOperand);

        return children;
    }

    @Override
    public IRNode build(List<IRNode> children) {
        return new BINOP(operator, children.get(0), children.get(1));
    }
}
